package com.szbmyoubao.app.ui.preview

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.szbmyoubao.app.view.dialog.downVideo
import com.ellecity06.common.base.BaseMvvmFragment
import com.ellecity06.common.base.BaseViewModel
import com.ellecity06.cwhiskymall.databinding.FragmentPreviewVideoBinding

/**
 * @author ellecity06
 * @time 2025/3/16 18:54
 * @des
 */
class PreviewVideoFragment : BaseMvvmFragment<FragmentPreviewVideoBinding, BaseViewModel>() {
    private val videoUrl: String? by lazy { arguments?.getString(URL) }

    companion object {
        private const val URL = "key_url"

        @JvmStatic
        fun newInstance(url: String): PreviewVideoFragment {
            val fragment = PreviewVideoFragment()
            val bundle = Bundle().apply {
                putString(URL, url)
            }
            fragment.arguments = bundle
            return fragment
        }

    }

    override fun lazyInit() {
        binding.ivDownload.setOnClickListener {
            videoUrl?.let {
               requireActivity(). downVideo(it,"")
            }

        }
        binding.videoView.backButton.visibility = View.GONE
        binding.videoView.fullscreenButton.visibility = View.GONE
        binding.videoView.setIsTouchWiget(false)
        binding.videoView.setUp(videoUrl, true, "")
        binding.videoView.startPlayLogic()
    }

    override fun onResume() {
        binding.videoView.onVideoResume()
        super.onResume()
    }

    override fun onPause() {
        binding.videoView.onVideoPause()
        super.onPause()
    }

    override fun onDestroyView() {
        binding.videoView.release()
        super.onDestroyView()
    }

    override fun onDestroy() {
        super.onDestroy()

    }

    override fun inflateBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentPreviewVideoBinding {
        return FragmentPreviewVideoBinding.inflate(inflater, container, false)
    }
}
